package com.develop.skwen.ourrules.view;

import android.app.Activity;
import android.content.res.Resources;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;

import com.develop.skwen.ourrules.basic.Presenter;
import com.develop.skwen.ourrules.basic.Vu;

/**
 * Created by skwen
 * on 18-4-24
 */

public abstract class BaseView<P extends Presenter> implements Vu<P> {

    private Activity mActivity;
    private P mPresenter;
    private View mView;

    @Override
    public <A extends Activity> void setActivity(A activity) {
        mActivity = activity;
    }

    @Override
    public void setPresenter(P presenter) {
        mPresenter = presenter;
    }

    public Activity getActivity() {
        return mActivity;
    }

    public P getPresenter() {
        return mPresenter;
    }

    @Override
    public void init() {
        mView = LayoutInflater.from(mActivity).inflate(getLayoutRes(),null,false);
        initViews();
    }

    protected abstract @LayoutRes int getLayoutRes();

    protected abstract void initViews();

    @Override
    public View getView() {
        return mView;
    }


    protected Resources getResources(){
        return mActivity.getResources();
    }

    protected String getStringRes(@StringRes int id){
        return getResources().getString(id);
    }

    protected <V extends View> V findViewById(@IdRes int id){
        return mView.findViewById(id);
    }

}
